import FSMMonster from "./FSMMonster";
import { IndicatorColorType } from "./Indicator";
import { FSMState } from "./lib/FSMState";
import Move from "./Move";

export default class MonsterChaseState extends FSMState {
    private _speed: number = 200;

    private _move: Move = null;
    private _monster: FSMMonster = null;

    onEnter() {
        super.onEnter();
        this._move = this.fsm.node.getComponent(Move);
        this._move.speed = this._speed;
        this._monster = this.fsm.node.getComponent(FSMMonster);
    }

    public update(dt: any): void {
        //玩家退出金币范围
        if (this._monster.player.getPosition().subSelf(this._monster.gold.getPosition()).len() >= this._monster.goldRange) {
            this.fsm.data.setData("isHeroOutGoldRange", true);
            this._monster.indicator.setColorType(IndicatorColorType.SAFE);
        } else {
            this._move.moveToDestination(this._monster.player.getPosition());
        }
    }

    public onEixt(): void {
        this._move.stop();
        super.onEixt();
    }
}
